/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package flightlifter;

/**
 *
 * @author Matt
 */
public class Ray {

    PVector origin;
    PVector dir;
    float length = 99999;
    public float minDist = 0.0f;
    public float maxDist = 1e6f;
    public float a, b;
    public float distance = -1;
    public float u, v;
    public float tu, tv;
    //what it ran into
    public Intersectable occluder = null;

    public Ray(PVector origin, PVector dir, float length) {
        this.origin = origin;
        this.dir = dir;
        this.length = length;
    }

    public String toString() {
        return "Origin: " + origin + " Dir: " + dir;
    }

    public float distToPoint(PVector point) {

        float ret = 0;

        PVector AP = PVector.sub(point, origin);
        PVector AB = PVector.sub(PVector.add(origin, PVector.mult(dir, 100)), origin);

        float ab2 = AB.x * AB.x + AB.y * AB.y + AB.z * AB.z;
        float ap_ab = PVector.angleBetween(AB, AP);


        return ap_ab / (float) Math.sqrt(ab2);

    }
}
